import 'dart:core';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:example/config/color_config.dart';
import '../../widget/search_text_field.dart';


enum PublicHandleItemStatyEnum {
  disableClick,//禁止点击 无交互
  select,      //选择操作
  edit,        //输入操作
}

class PublicDataSource {
  String? leftTitle;
  String? name;
  String? subName;
  String? subName2;
  num?    index;
  String? subTitle;
  String? placeHodlerStr;
  String? placeHodlerImagePath;
  String? hintStr;
  String? content;
  String? content2;
  String? imageName;
  String? routeName;
  Color?  bgColor;
  Color?  textColor;
  Color?  leftTitleColor;
  Color?  contentColor;
  bool?   fillinStyle; //是否必填 true 必填
  bool?   selectStaty;
  PublicHandleItemStatyEnum? handleStatyEnum;
  MySearchController? searchController;
  List<TextInputFormatter>? inputFormatters;
  TextInputType? keyboardType;

  List<PublicDataSource>? dataSource;
  num? id;
  String? code;
  int? maxLength;

  PublicDataSource({
    this.leftTitle,
    this.name,
    this.subName,
    this.subName2,
    this.index,
    this.subTitle,
    this.placeHodlerStr,
    this.placeHodlerImagePath,
    this.hintStr,
    this.content,
    this.content2,
    this.imageName,
    this.routeName,
    this.bgColor = Colors.transparent,
    this.textColor,
    this.leftTitleColor = ColorConfig.text,
    this.fillinStyle,
    this.handleStatyEnum = PublicHandleItemStatyEnum.edit,
    this.searchController,
    this.inputFormatters,
    this.keyboardType = TextInputType.name,
    this.selectStaty,
    this.contentColor = ColorConfig.text,
    this.dataSource,
    this.id,
    this.code,
    this.maxLength
  });

  bool canEdit(){
    if(handleStatyEnum == PublicHandleItemStatyEnum.edit){
      return true;
    }
    return false;
  }

}

class ChinaAddress {
  List<ChinaAddress>? children;
  String? id;
  String? name;

  ChinaAddress({
    this.children,
    this.id,
    this.name,
  });

  factory ChinaAddress.fromJson(Map<String, dynamic> json) => ChinaAddress(
    children: List<ChinaAddress>.from(json["children"].map((x) => ChinaAddress.fromJson(x))),
    id: json["id"],
    name: json["name"],
  );

  Map<String, dynamic> toJson() => {
    "children": List<dynamic>.from(children!.map((x) => x.toJson())),
    "id": id,
    "name": name,
  };
}
